#include<iostream>
using namespace std;
const int N = 1e5 + 10;
int arr[N];
int q[N];
int n;
int main()
{
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> arr[i];
	}
	int len = 0;
	q[0] = -2e9;
	for (int i = 0; i < n; i++) {
		int l = 0;
		int r = len;
		while (l < r) {
			int mid = l + r + 1>> 1;	
			if (q[mid] < arr[i]) {
				l = mid;
			}
			else {
				r = mid - 1;
			}
		}
		q[r + 1] = arr[i];
		len = max(len, r + 1);
	}
	cout << len << endl;
	return 0;
}	